<?php

class Empeval_Methods_Request_SetBonusGoalsFromPeriod {
	
	/**
	 *
	 * @var App_Methods_Data_App
	 */
	public $app;
	public $bonusGoalsFormId;
	public $bonusPeriodId;
	public $year;
	
	public function __construct($params) {
		$this->app = new App_Methods_Data_App($params->app);
		$this->bonusGoalsFormId = (int)$params->bonusGoalsFormId;
		$this->bonusPeriodId = (int)$params->bonusPeriodId;
		$this->year = (int)$params->year;
	}
	
	public function process() {
		$bonusGoalsForm = EmpevalBonusGoalsFormsQuery::create()
		->filterById($this->bonusGoalsFormId)
		->filterByEditorId(Empeval_Auth::getInstance()->getUser()->getId())
		->findOne();
		
		if (!($bonusGoalsForm instanceof EmpevalBonusGoalsForms))
			throw new Empeval_Exception_App(Empeval_Exception_Codes::INFO_ACCESS_DENIED);
		
		if ($this->bonusPeriodId != null)
			$bonusGoalsForm->setBonusPeriodId($this->bonusPeriodId);
		$bonusGoalsForm->setYear($this->year);
		$bonusGoalsForm->save();
		
		return new Empeval_Methods_Response_SetBonusGoalsFromPeriod(true, $bonusGoalsForm);
	}
	
}